
#include <Stdio.h>

#include <Windows.h>

//////////////////////////////////////////////////////////////////////////

int main()
{
	HANDLE hFileHZK = CreateFile("ASC12", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
	HANDLE hFileCPP = CreateFile("ASC12.Cpp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);

	CHAR szStart[]	= "extern const unsigned char ASC12[] = \n{\n";
	CHAR szFinish[]	= "};\n";

	UCHAR szBufferHZK[32] = { 0 };
	CHAR szBufferCPP[2048] = { 0 };

	DWORD dwRead = 0;
	DWORD dwWritten = 0;
	ULONGLONG llFileSize = GetFileSize(hFileHZK, NULL);
	DWORD dwCount = 0;

	if (!::WriteFile(hFileCPP, szStart, sizeof(szStart)-1, &dwWritten, NULL)) {
		goto Exit;
	}

	dwCount = llFileSize/sizeof(szBufferHZK);
	for (DWORD i=0; i<dwCount; ++i) {
		if (!::ReadFile(hFileHZK, szBufferHZK, sizeof(szBufferHZK), &dwRead, NULL)) {
			goto Exit;
		}

		wsprintf(szBufferCPP, 
			"0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,\n", 
			szBufferHZK[0], szBufferHZK[1], szBufferHZK[2], szBufferHZK[3], szBufferHZK[4], szBufferHZK[5], szBufferHZK[6], szBufferHZK[7], 
			szBufferHZK[8], szBufferHZK[9], szBufferHZK[10], szBufferHZK[11], szBufferHZK[12], szBufferHZK[13], szBufferHZK[14], szBufferHZK[15], 
			szBufferHZK[16], szBufferHZK[17], szBufferHZK[18], szBufferHZK[19], szBufferHZK[20], szBufferHZK[21], szBufferHZK[22], szBufferHZK[23], 
			szBufferHZK[24], szBufferHZK[25], szBufferHZK[26], szBufferHZK[27], szBufferHZK[28], szBufferHZK[29], szBufferHZK[30], szBufferHZK[31]);

		if (!::WriteFile(hFileCPP, szBufferCPP, strlen(szBufferCPP), &dwWritten, NULL)) {
			goto Exit;
		}
	}

	if (!::WriteFile(hFileCPP, szFinish, strlen(szFinish), &dwWritten, NULL)) {
		goto Exit;
	}

Exit:
	CloseHandle(hFileHZK);
	CloseHandle(hFileCPP);
	return 0;
}
